initSearchWindow = function() {
	if (Ext.getCmp('searchWin') != null) {
		Ext.getCmp('searchWin').show();
		return;
	}
	new Ext.Window( {
		title : searchwindowTitle,
		width : 350,
		height : 500,
		id : 'searchWin',
		animateTarget : 'searchMenu',
		plain : true,
		closable : true,
		autoScroll : true,
		closeAction : 'hide',
		constrain: true,
		constrainHeader: true,
		/*initDraggable : function(){
        this.dd = new Ext.Window.DD(this);  
        this.dd.onDrag = function(e){
            this.alignElWithMouse(this.proxy, e.getPageX(), Math.max(10+this.deltaY, e.getPageY()));
        }.bind(this.dd);
    },*/
		listeners : {
			
			'beforehide' : function() {
				Ext.get('searchMenu').show();
				counter = 10;
			},
			'afterrender' : function() {
				//Ext.get('searchWin').setPosition(20, 125);
								this.setPosition(20, 125);

					},
			'beforeshow' : function() {
				Ext.get('searchMenu').hide();

			}
		}
	});//.hide();
};

showSearchWindow = function() {
	var searchWin = Ext.getCmp('searchWin');
	searchWin.show();
	if (local=='ar'){ 
	searchWin.setPosition(900,125);
	
	}
	else
		{
		searchWin.setPosition(20,125);
	
		}
	//alert('x'+Ext.getCmp('searchWin').x+ ' y '+Ext.getCmp('searchWin').y);
	if (Ext.getCmp('searchTabs') == null) {
		initDrugForm();

		loadSearchWindow(searchWin);
	}

};


loadSearchWindow = function(searchWin) {

	//createDrugListForm();
	//addSearchResultGrid();
	var drug = Ext.data.Record.create( [ {
		name : 'drugId',
		type : 'drugId'
	}, {
		name : 'drugName',
		type : 'drugName'
	}, {
		name : 'adrugName',
		type : 'adrugName'
	} ]);

	var proxy = new Ext.data.HttpProxy( {
		api : {
			read : 'getDrugs.html'
		}
	});

	var reader = new Ext.data.JsonReader( {
		totalProperty : 'total',
		successProperty : 'success',
		idProperty : 'drugId',
		root : 'drugModel',
		messageProperty : 'message' // <-- New "messageProperty" meta-data
	}, drug);

	var drugStore = new Ext.data.Store( {
		id : 'drugStore',
		proxy : proxy,
		reader : reader
	});

	drugStore.load( {
		params : {
			start : 0,
			limit : 5
		}
	});

	drugStore.on( {
		'load' : {
			fn : function(drugStore, records, options) {
				//store is loaded, now you can work with it's records, etc.
			var len = drugStore.getCount();
			var searchTabAccordian = new Ext.Panel( {
				margins : '5 0 5 5',
				split : true,
				autoScroll : true,
				id : 'searchTotal',
				width : 310,
				layout : 'accordion'
			});

			for ( var i = 0; i < len; i++) {
				drugName = drugStore.getAt(i).json.drugName;
				adrugName = drugStore.getAt(i).json.adrugName;

				if (languageName == 'arabic') {
					drugNameTitle = adrugName;
				} else {
					drugNameTitle = drugName;
				}

				if (i == 0) {
					var pan = createSearchForm(i, drugNameTitle);

					pan = Ext.getCmp(drugNameTitle);

					searchTabAccordian.add(new Ext.Panel( {
						width : 320,
						title : drugNameTitle,
						iconCls : drugName,
						autoscroll : true,
						height : 500,
						layout : 'fit',
						id : i,
						items : [ pan ]
					}));
					firstDrug = drugNameTitle;
					var myPanel1 = Ext.getCmp(i);
					myPanel1.on('resize', function(panel, w, h) {

						var drug1 = this.title;
						var c = this.id;

						if (counter > 11) {
							this.removeAll();
							createSearchForm(c, drug1);
							var pan = Ext.getCmp(drug1);
							this.add(pan);
						}
						counter = counter + 1;

					});

				} else {
					searchTabAccordian.add(new Ext.Panel( {
						width : 320,
						title : drugNameTitle,
						iconCls : drugName,
						autoscroll : true,
						layout : 'fit',
						id : i
					}));

					var myPanel = Ext.getCmp(i);
					myPanel.on('resize', function(panel, w, h) {
						counter = counter + 1;
						var drug1 = this.title;
						var c = this.id;

						if (counter > 10) {
							this.removeAll();
							createSearchForm(c, drug1);
							var pan = Ext.getCmp(drug1);
							this.add(pan);
						}

					});
				}
			}

			searchResults = {
				id : 'searchResults_id',
				layout : 'fit',
				border : false,
				iconCls : 'qs_ico',
				title : resultsTitle,
				height : 200
			};

			var searchTabAccordian = Ext.getCmp('searchTotal');
			var searchItems = {
				id : 'searchItems_id',
				layout : 'fit',
				border : false,
				iconCls : 'qs_ico',
				title : searchbyTitle,
				height : 540,
				listeners : {
					activate : handleActivate
				},
				items : [ searchTabAccordian ]
			};

			Searchinfo = new Ext.TabPanel( {
				id : 'Searchinfo',
				plain : true,
				activeTab : 0,
				border : false,
				title : searchTitle,
				iconCls : 'my-icon',
				height : 550,
				items : [ searchItems, searchResults ]
			});
			var ComparisionMain = new Ext.TabPanel( {
				id : 'ComparisionMain_id',
				plain : true,
				//layout: 'fit',
				activeTab : 0,
				border : false,
				title : 'ComparisionMain',
				iconCls : 'my-icon',
				height : 400,
				//items:[searchTabAccordian]
				items : [ drugCompareForm ]
			//,comparisionResults]
					});

			camparision = {
				id : 'camparision',
				layout : 'fit',
				border : false,
				iconCls : 'my-icon',
				title : comparisonTitle,
				height : 400,
				items : [ ComparisionMain ]

			};

			var searchTabs = new Ext.TabPanel( {
				margins : '3 3 3 0',
				activeTab : 0,
				style : 'background:none',
				plain : true,
				id : 'searchTabs',
				baseCls : 'srcTab',
				frame : false,
				border : false,
				items : [ Searchinfo, camparision ]
			});

			//refresh the searchWin contents
			searchWin.add(searchTabs);
			searchWin.doLayout();

		}
	}
})	;
};
function handleActivate() {

	if ((searchvectors != null) && (searchvectors != "")) {
		mapObj.removeLayer(searchvectors);
		searchvectors = "";
	}
	var win = Ext.getCmp('winChart');
	if (win != null)
		win.close();
	if (Ext.getCmp('measureWin') != null)
		Ext.getCmp('measureWin').hide();
	var ele = document.getElementById("legendpan");

	ele.style.display = "none";
}